<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#div1{
				width:100px;
				height:100px;
				background: red;
				position:absolute;
				top:100px;
				left:0px;
			}
		</style>
	</head>
	<body>
		<script>
			window.onload = function(){
				var oDiv = document.getElementById("div1");
				var btn = document.getElementsByTagName('input')[0];
				var timer = null;
				btn.onclick = function(){
					move(oDiv,10,800);
				}
				
				function move(obj,speed,target){
					timer = setInterval(function(){
						var oldLeft = obj.offsetLeft;
						
						if(oldLeft>target || oldLeft<0){
							speed = -speed;
						}
						var newLeft = oldLeft + speed;
//						console.log(typeof oldLeft)
						obj.style.left = newLeft + 'px';
					},1000/60);console.log(oDiv)
				}
				
				
				
				 
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
			}
		</script>
		<input type="button" value="开始" />
		<div id="div1"></div>
	</body>
</html>
